import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from face_recognition import FaceRecognition
import logging

def main():
    # 设置日志级别
    logging.basicConfig(level=logging.INFO)
    
    try:
        # 初始化人脸识别模块
        recognizer = FaceRecognition()
        
        # 添加新人脸
        name = input("请输入要添加的人员姓名: ")
        success, message = recognizer.add_person(name)
        print(message)
        
        # 无论是否成功添加人员，都进行识别测试
        print("\n现在进行识别测试，请面对摄像头...")
        result = recognizer.recognize_with_timeout(timeout=5, show_preview=False)
        
        if result:
            print(f"\n识别结果:")
            print(f"姓名: {result['person_name']}")
            print(f"置信度: {result['confidence']:.2f}%")
        else:
            print("\n未能识别到人脸")
                
    except KeyboardInterrupt:
        print("\n程序被用户中断")
    except Exception as e:
        print(f"发生错误: {e}")

if __name__ == '__main__':
    main() 